package 课上练习0419_scala_collection

object Scala_06WordCount extends App {
  val words = List("hello world", "args should not", "what the fuck", "hello bro")

  words.flatMap(_.split("\\s+"))
    .map((_, 1))
    .groupBy(_._1)
    .view.mapValues(_.length)
    .toList.sortBy(_._2).reverse
    //topN
    .take(3)
    .foreach(println)
}
